/**
 * 
 */
package org.yatr.ttcn.rt.impl;

import org.etsi.ttcn.tci.TciBehaviourId;
import org.etsi.ttcn.tci.TciCHProvided;
import org.etsi.ttcn.tci.TciCHRequired;
import org.etsi.ttcn.tci.TciParameterList;
import org.etsi.ttcn.tci.TciTestCaseId;
import org.etsi.ttcn.tci.TciTestComponentKind;
import org.etsi.ttcn.tci.Type;
import org.etsi.ttcn.tci.Value;
import org.etsi.ttcn.tci.VerdictValue;
import org.etsi.ttcn.tri.TriComponentId;
import org.etsi.ttcn.tri.TriPortId;
import org.etsi.ttcn.tri.TriPortIdList;
import org.etsi.ttcn.tri.TriSignatureId;
import org.yatr.tci.TciCDRequiredYatr;
import org.yatr.ttcn.rt.RO;

/**
 * @author lvjinhua
 *
 */
public class TciCHRequiredImpl extends TciCDRequiredYatr implements TciCHRequired {
	private ATSTable atsTable;
	private RO ro;
	private TciCHProvided chProvided;
	
	public TciCHRequiredImpl(RO ro, ATSTable atsTable) {
		this.ro = ro;
		this.atsTable = atsTable;
		this.chProvided = ro.getTciCHProvided();
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciConnect(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriPortId)
	 */
	public void tciConnect(TriPortId fromPort, TriPortId toPort) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciCreateNamedTestComponent(int, org.etsi.ttcn.tci.Type, java.lang.String)
	 */
	public TriComponentId tciCreateNamedTestComponent(int kind,
			Type componentType, String id) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciCreateTestComponent(int, org.etsi.ttcn.tci.Type)
	 */
	public TriComponentId tciCreateTestComponent(int kind, Type componentType) {
		return tciCreateTestComponent(kind, componentType, null);
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciCreateTestComponent(int, org.etsi.ttcn.tci.Type, java.lang.String)
	 */
	public TriComponentId tciCreateTestComponent(int kind, Type componentType,
			String name) {
		Component comp = (Component)((ComponentType)componentType).newInstance();		
		TriComponentId cid = TypeFactory.newTriComponentId(componentType.getDefiningModule().getModuleName(), componentType.getName());
		
		switch(kind) {
			case TciTestComponentKind.TCI_CTRL_COMP:
			{
				System.out.println("create Control Component");
				break;
			}
			case TciTestComponentKind.TCI_MTC_COMP:
			{
				System.out.println("create MTC Component");
				break;
			}
			case TciTestComponentKind.TCI_PTC_COMP:
			{
				System.out.println("create PTC Component");
				break;
			}
			default:
			{
				System.out.println("create Unknown Component="+kind);
				break;
			}
		}
		comp.setCompKind(kind);
		comp.setComponnetId(cid);
		atsTable.addComponent(cid, comp);
		return cid;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciDisconnect(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriPortId)
	 */
	public void tciDisconnect(TriPortId fromPort, TriPortId toPort) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciEnqueueCallConnected(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tri.TriSignatureId, org.etsi.ttcn.tci.TciParameterList)
	 */
	public void tciEnqueueCallConnected(TriPortId senderPort,
			TriComponentId receiverComp, TriSignatureId signature,
			TciParameterList parameterList) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciEnqueueMsgConnected(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tci.Value)
	 */
	public void tciEnqueueMsgConnected(TriPortId senderPort,
			TriComponentId receiverComp, Value receivedMessage) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciEnqueueRaiseConnected(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tri.TriSignatureId, org.etsi.ttcn.tci.Value)
	 */
	public void tciEnqueueRaiseConnected(TriPortId senderPort,
			TriComponentId receiverComp, TriSignatureId signature, Value except) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciEnqueueReplyConnected(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tri.TriSignatureId, org.etsi.ttcn.tci.TciParameterList, org.etsi.ttcn.tci.Value)
	 */
	public void tciEnqueueReplyConnected(TriPortId senderPort,
			TriComponentId receiverComp, TriSignatureId signature,
			TciParameterList parameterList, Value returnValue) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciExecuteTestCase(org.etsi.ttcn.tci.TciTestCaseId, org.etsi.ttcn.tri.TriPortIdList)
	 */
	public void tciExecuteTestCase(TciTestCaseId TestCaseId,
			TriPortIdList tsiPortList) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciGetMTC()
	 */
	public TriComponentId tciGetMTC() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciKillTestComponent(org.etsi.ttcn.tri.TriComponentId)
	 */
	public void tciKillTestComponent(TriComponentId component) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciMap(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriPortId)
	 */
	public void tciMap(TriPortId fromPort, TriPortId toPort) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciReset()
	 */
	public void tciReset() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciStartTestComponent(org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tci.TciBehaviourId, org.etsi.ttcn.tci.TciParameterList)
	 */
	public void tciStartTestComponent(TriComponentId comp,
			TciBehaviourId behavior, TciParameterList parameterList) {
		atsTable.startTestComponent(comp, behavior, parameterList);
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciStopTestComponent(org.etsi.ttcn.tri.TriComponentId)
	 */
	public void tciStopTestComponent(TriComponentId comp) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciTestComponentAlive(org.etsi.ttcn.tri.TriComponentId)
	 */
	public boolean tciTestComponentAlive(TriComponentId component) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciTestComponentDone(org.etsi.ttcn.tri.TriComponentId)
	 */
	public boolean tciTestComponentDone(TriComponentId comp) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciTestComponentKilled(org.etsi.ttcn.tri.TriComponentId)
	 */
	public boolean tciTestComponentKilled(TriComponentId component) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciTestComponentRunning(org.etsi.ttcn.tri.TriComponentId)
	 */
	public boolean tciTestComponentRunning(TriComponentId comp) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciTestComponentTerminated(org.etsi.ttcn.tri.TriComponentId, org.etsi.ttcn.tci.VerdictValue)
	 */
	public void tciTestComponentTerminated(TriComponentId comp,
			VerdictValue verdict) {
		ro.log("in tciTestComponentTerminated: compId="+comp+"\tverdict="+verdict.getVerdict());
		atsTable.testComponentTerminated(comp, verdict);
	}

	/* (non-Javadoc)
	 * @see org.etsi.ttcn.tci.TciCHRequired#tciUnmap(org.etsi.ttcn.tri.TriPortId, org.etsi.ttcn.tri.TriPortId)
	 */
	public void tciUnmap(TriPortId fromPort, TriPortId toPort) {
		// TODO Auto-generated method stub

	}
}
